package n1195;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	
	static int[][] trr=new int[1026][1026];
	
	static int S;
	
	static int lowbit(int x)
	{
		return x&(-x);
	}
	
	static void modify(int x,int y,int a)
	{
		for(int i=x;i<S;i+=lowbit(i))
			for(int j=y;j<S;j+=lowbit(j))
			{
				trr[i][j]+=a;
			}
	}
	
	
	static int sum(int x,int y)
	{
		int ans=0;
		for(int i=x;i>0;i-=lowbit(i))
			for(int j=y;j>0;j-=lowbit(j))
			{
				ans+=trr[i][j];
			}
		return ans;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		String line=null;
		while((line=bf.readLine())!=null)
		{
			String[] st=line.split("\\s+");
			if(st[0].equals("3"))break;
			if(st[0].equals("1"))
			{
				int x=Integer.parseInt(st[1])+1;
				int y=Integer.parseInt(st[2])+1;
				int a=Integer.parseInt(st[3]);
				modify(x, y, a);
			}else if(st[0].equals("2"))
			{
				int x1=Integer.parseInt(st[1])+1;
				int y1=Integer.parseInt(st[2])+1;
				int x2=Integer.parseInt(st[3])+1;
				int y2=Integer.parseInt(st[4])+1;
				System.out.println(sum(x2,y2)-sum(x2,y1-1)-sum(x1-1,y2)+sum(x1-1, y1-1));
				
			}else if(st[0].equals("0"))
			{
				S=Integer.parseInt(st[1])+1;
			}
		}
		
	}

}
